package com.atguigu.gulimall.order.vo;

import lombok.Data;
import lombok.Getter;
import lombok.Setter;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * 订单确认页需要用的数据
 */
//@Data
public class OrderConfirmVo {

    // 收货地址列表
    @Setter
    @Getter
    private List<MemberAddressVo> address;
    // 所有选中的购物项
    @Setter
    @Getter
    private List<OrderItemVo> items;
    // 发票记录
    // 优惠券信息
    @Setter
    @Getter
    private Integer integration;
    // 订单总额
    private BigDecimal total;
    // 应付价格
    private BigDecimal payPrice;
    // 订单防重令牌
    @Setter
    @Getter
    private String orderToken;

    @Setter
    @Getter
    Map<Long, Boolean> stocks;

    public BigDecimal getTotal() {

        BigDecimal sum = new BigDecimal("0");
        if (this.items != null) {
            for (OrderItemVo item : items) {
                BigDecimal multiply = item.getPrice().multiply(new BigDecimal(item.getCount().toString()));
                sum = sum.add(multiply);
            }
        }
        return sum;
    }

    public BigDecimal getPayPrice() {
        return this.getTotal();
    }

    public Integer getCount() {
        Integer i = 0;
        if (items != null) {
            for (OrderItemVo item : items) {
                i += item.getCount();
            }
        }
        return i;
    }
}
